Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Part block: Fix template part path arg missing from actions #56790

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Dec 5, 2023

What?

In the Template Part block, set the $template_part_file_path variable (for use by the render_block_core_template_part_file and render_block_core_template_part_none filters).

Why?

Fixes #56013. This was broken by #52892.

How?

By calling _get_block_template_file() (which duplicates some logic also found deeper in the call stack of get_block_file_template). But alas, the relevant information cannot be inferred from the WP_Block_Template object returned by get_block_file_template, nor does the eponymous filter expose any useful information.

Testing Instructions

Quoting #56013:

add_action( 'render_block_core_template_part_file', function( $template_part_id, $attributes, $template_part_file_path ) {
    var_dump( $template_part_file_path );
}, 10, 3 );

Load the front page of a vanilla WordPress site using the Twenty Twenty Four theme and observe that [...] the template part file path [is logged].

This [fix] can also be [tested] by installing the Query Monitor plugin and viewing the "Template" panel, which [should show] the path to each Template Part block that was loaded on the page.

@ockham ockham added [Type] Bug An existing feature does not function as intended [Block] Template Part Affects the Template Parts Block labels Dec 5, 2023
@ockham ockham self-assigned this Dec 5, 2023
Copy link

github-actions bot commented Dec 5, 2023

Flaky tests detected in dddcea7.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7102449719
📝 Reported issues:

@ockham ockham marked this pull request as ready for review December 5, 2023 17:09
@ockham ockham force-pushed the fix/missing-template-part-file-path-in-template-part-block-actions branch from dddcea7 to 08cd893 Compare January 3, 2024 12:33
Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this and it's working as expected, it fixes the mentioned issue.

@ockham ockham merged commit 0ee537d into trunk Jan 3, 2024
55 checks passed
@ockham ockham deleted the fix/missing-template-part-file-path-in-template-part-block-actions branch January 3, 2024 14:47
@github-actions github-actions bot added this to the Gutenberg 17.5 milestone Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Template part file path is no longer passed to the render_block_core_template_part_file action
2 participants